package com.ruoyi.user.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.user.domain.bo.UserChdjResultBo;
import com.ruoyi.user.domain.vo.UserChdjResultVo;
import com.ruoyi.user.service.IUserChdjResultService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 查获登记结果
 *
 * @author strongme
 * @date 2023-01-26
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/user/chdjResult")
public class UserChdjResultController extends BaseController {

    private final IUserChdjResultService iUserChdjResultService;

    /**
     * 查询查获登记结果列表
     */
    @GetMapping("/list")
    public TableDataInfo<UserChdjResultVo> list(UserChdjResultBo bo, PageQuery pageQuery) {
        return iUserChdjResultService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出查获登记结果列表
     */
    @Log(title = "查获登记结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(UserChdjResultBo bo, HttpServletResponse response) {
        List<UserChdjResultVo> list = iUserChdjResultService.queryList(bo);
        ExcelUtil.exportExcel(list, "查获登记结果", UserChdjResultVo.class, response);
    }

    /**
     * 获取查获登记结果详细信息
     *
     * @param chdjResultId 主键
     */
    @GetMapping("/{chdjResultId}")
    public R<UserChdjResultVo> getInfo(@NotNull(message = "主键不能为空")
                                       @PathVariable Long chdjResultId) {
        return R.ok(iUserChdjResultService.queryById(chdjResultId));
    }

    /**
     * 根据查获登记ID获取查获登记结果列表
     *
     * @param chdjId
     * @return
     */
    @GetMapping("/byChdjId/{chdjId}")
    public R<List<UserChdjResultVo>> getInfoByChdjId(@NotNull(message = "主键不能为空")
                                                     @PathVariable Long chdjId) {
        return R.ok(iUserChdjResultService.queryByChdjId(chdjId));
    }


    /**
     * 新增查获登记结果
     */
    @Log(title = "查获登记结果", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserChdjResultBo bo) {
        return toAjax(iUserChdjResultService.insertByBo(bo));
    }

    /**
     * 修改查获登记结果
     */
    @Log(title = "查获登记结果", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserChdjResultBo bo) {
        return toAjax(iUserChdjResultService.updateByBo(bo));
    }

    /**
     * 删除查获登记结果
     *
     * @param chdjResultIds 主键串
     */
    @Log(title = "查获登记结果", businessType = BusinessType.DELETE)
    @DeleteMapping("/{chdjResultIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] chdjResultIds) {
        return toAjax(iUserChdjResultService.deleteWithValidByIds(Arrays.asList(chdjResultIds), true));
    }
}
